import ChiVoxSDK from 'chivox';
import Config from './config';

import $ from 'jquery';
import '../css/chivox-example.css';

let mode = ChiVoxSDK.MODE.HTML5;
//let mode = ChiVoxSDK.MODE.FLASH;

let A = {
    "qid": "PAPER-000005-QT-000024",
    "lm": [{
        "answer": 1,
        "text": "I'm in a great class. There are thirty boys and twenty eight girls. All of us get on well with each other. We can also help each other often. All the students in T1: my class are hard working. I believe each student in my class will have a bright future."
    }, {
        "answer": 1,
        "text": "There are thirty boys and twenty eight girls in my class. Everybody here gets along well with each other. And we often learn from each other and help with each T1: other. We study hard because you know that there is a dream in every teenager's heart."
    }, {
        "answer": 1,
        "text": "Hello! Nice to meet you. Nice to see you. I will introduce my class to you. There are thirty boys and twenty eight girls in my class. Each of them gets on well with each other, and often helps others. I'm proud to say that we all work hard. What's a wonderful group! I hope you'll have the chance to get familiar with every one!"
    }, {
        "answer": 1,
        "text": "Our class is made up of thirty boys and twenty eight girls. Both of us get along well with each other and are even helpful. We study really hard. All the time."
    }, {
        "answer": 1,
        "text": "There are thirty boys as well as twenty eight girls in our class. We get along with each other can help each other. We are very hard working. I hope someday we can be successful in getting into university together."
    }, {
        "answer": 1,
        "text": "There are thirty boys and twenty eight girls in our class. We get along well with each other and can help with each other. What's more, we study hard all the time."
    }, {
        "answer": 1,
        "text": "There are thirty boys and twenty eight girls in our class. We get well with others and help each other. Now, we are working hard in our study."
    }, {
        "answer": 1,
        "text": "There are thirty boys and twenty eight girls in our class. We all get on well with each other and help each other. We all study hard."
    }, {
        "answer": 1,
        "text": "There are thirty boys and twenty eight girls in my class. Everyone gets with each other well. We can help each other. We study very hard."
    }, {
        "answer": 1,
        "text": "There are thirty boys and twenty eight girls in my class. We get well along with each other. We often help with each other too. We study hard."
    }, {
        "answer": 1,
        "text": "There are thirty boys and twenty eight girls in my class. We get along with each other very well and we also learn from each other. Besides, we are all hard making."
    }, {
        "answer": 1,
        "text": "There are thirty boys and twenty eight girls in our class. We help each other and get along well with each other. We all study very hard."
    }, {
        "answer": 0,
        "text": "There are thirty boys and twenty eight girls in my class. We get along well with everyday and we can help with each other. We are very hard working."
    }, {
        "answer": 0,
        "text": "There are thirty boys and twenty eight girls in my class. We can get along well, and we often help with each other.We study very hard."
    }, {
        "answer": 0,
        "text": "There's thirty boys and twenty eight girls in my class. We get along well. We often help with each other. We all work hard."
    }, {
        "answer": 0,
        "text": "There are thirty boys and twenty eight girls in my class. We get well with each other and can help with each other, too. We study very hard."
    }, {
        "answer": 0,
        "text": "There are thirty boys and twenty-eight girls in my class. We get on well with each other, and we can also help with each other. We all study very hard."
    }, {
        "answer": 0,
        "text": "There're thirty boys and twenty eight girls in my class. We get along well with each other and we often help each other. All the student work hard."
    }, {
        "answer": 0,
        "text": "My class has thirty boys and twenty eight girls. We get along well with each other and we can help from each other. We study well and hard."
    }, {
        "answer": 0,
        "text": "There're thirty boys and twenty-eight girls in my class. We help with each other. We study hard."
    }, {
        "answer": 0,
        "text": "There are thirty boys and twenty-two girls in my class. We all get along well with each other. We study very hard. I love my class very much."
    }, {
        "answer": 0,
        "text": "There are thirty boys and twenty eight girls in my class. We get along well with each other. We can each other. We are hard working."
    }, {
        "answer": 0,
        "text": "There are thirty boys and twenty eight girls in my class. We can get along well with each other. Also, we can help each other. We study very hard."
    }, {
        "answer": 0,
        "text": "There are thirsty boys and twenty-eight girls is my class. We are getting along well with each other and we can help each other. We are working hard."
    }, {
        "answer": 0,
        "text": "There is thirty boys and twenty eight girls in my class. We are all get on well with each other. We all all hard working."
    }, {
        "answer": 0,
        "text": "There are thirty boys and twenty-eight girls in my class. We have good"
    }, {
        "answer": 0,
        "text": "There are thirty boys and twenty-eight girls in our class. We get well with each other and often help each other. We study very hard."
    }, {
        "answer": 0,
        "text": "There are thirty boys and twenty eight girls in our clas, he yet well with each other, he works very hard."
    }, {
        "answer": 0,
        "text": "There are thirty boys and twenty-eight girls in my class, we are good friends, we can help from each other, we all study hard."
    }, {
        "answer": 0,
        "text": "There are thirty boys and twenty eight girls in my class, we get along well with each other. And we also help each other, of course, we learn hard."
    }, {
        "answer": 0,
        "text": "There are 38 boys and twenty eight girls in my class, we get along with each other and we learn from each other, and we study hard."
    }, {
        "answer": 0,
        "text": "There are thirty boys and twenty eight girls in my class, we get well with each other and can help from each other, we study very hard."
    }, {
        "answer": 0,
        "text": "There're thirty boys and twenty eight girls in my class, we get along well with each other we can help each other, too. We study very hard."
    }, {
        "answer": 0,
        "text": "There is thirty boys and twenty eight girls in my class, we get well alone with each other we study very hard."
    }, {
        "answer": 0,
        "text": "There are thirty boys and twenty eight girls in our class, all of us get well with each other. And we we can help each other. We studied very hard!"
    }, {
        "answer": 0,
        "text": "There are thirty boys and twenty eight girls in my classroom, we are getting along will and can help each other. We study very hard."
    }, {
        "answer": 0,
        "text": "Our class have thirty boys and twenty eight girls.we can help each other when someone of us I need. Of course, we are very hard-working in study."
    }, {
        "answer": 0,
        "text": "Our class has thirty boys and twenty-eight girls. Everyone gets along well and can help each other. We study hard."
    }, {
        "answer": 0,
        "text": "There are thirsty boys and twenty-eight girls in my class, we are getting along well with each other. We can help each other. We are also working hard."
    }, {
        "answer": 0,
        "text": "There are thirsty boys and twenty-eight girls in my class. We are getting along well with each other and We can help each other. We study very hard."
    }, {
        "answer": 0,
        "text": "There are thirty boys and twenty eight girls in my class and we are harmony with each other. We also can help each other. We are all study hardly."
    }, {
        "answer": 0,
        "text": "There are thirty boys and twenty eight girls in my class. We get along with each other. And help each other. We are all busy studying and study very hard."
    }, {
        "answer": 0,
        "text": "There are thirty boys and twenty eight girls in my class. Students go along well with each other. We are hard working."
    }, {
        "answer": 0,
        "text": "Our class has fifty eight students in total. There are thirty boys and twenty eight girls. We are getting along well with each other. We can help each other and share happiness with each other. We all study very hard. I love my class so much."
    }, {
        "answer": 0,
        "text": "There are thirsty boys and twenty eight girls in my class. We get along with well, and often help each other. He study hard."
    }, {
        "answer": 0,
        "text": "In our classroom. There are thirty boys and twenty eight girls. We get along with each other well. We also can help with each other. We study hard very much to achieve high work."
    }, {
        "answer": 0,
        "text": "There are thirty boys and twenty eight girls in my class. We get along with each other and we help each other too. We study very hard."
    }, {
        "answer": 0,
        "text": "There are fifty eight students in my class. Thirty of them are boys, the others are girls. We get along well with each other. We help each other. We study hard."
    }, {
        "answer": 0,
        "text": "There are thirty boys and twenty eight girls in our class. We get along with our students and can help with each other. We all very hardworking."
    }, {
        "answer": 0,
        "text": "there are thirty boys and twenty-eight girls in our class. All of us get well with each other, and help each other. We are working hard"
    }, {
        "answer": 0,
        "text": "There are thirty boys and twenty eight girls. We get along with well and help each other. We work very hard."
    }, {
        "answer": 0,
        "text": "There are thirty boys and twenty eight girls in my class. They get along well with and help with each other. We all study hard."
    }, {
        "answer": 0,
        "text": "There are thirty boys and twenty eight girls in my class. We get along well with everybody. And we can help each other. We all work hard."
    }, {
        "answer": 0,
        "text": "There are thirty boys and twenty eight girls in my class. They get along well with and help with each other. We all study hard."
    }, {
        "answer": 0,
        "text": "There are thirty boys and twenty eight girls in my class. We can help each other and get along well. We all study hard."
    }, {
        "answer": 0,
        "text": "There are thirty boys and twenty eight girls in my class. They get along well with others. And they can help each other. We study very hard."
    }, {
        "answer": 0,
        "text": "We class has thirty boys, and twenty eight girls. We get along with well, and we can help each other. We study very hard."
    }, {
        "answer": 0,
        "text": "There is thirty schoolboys and twenty eight girls in my class. We all have great along with others, And we can help each other. We all study very hard."
    }, {
        "answer": 0,
        "text": "There are thirty boys and twenty eight girls in my class. We get along well with each other And we help each other. We work hard."
    }, {
        "answer": 0,
        "text": "There are thirty boys and twenty-eight girls in our class. We get along well with each other And we help each other. We study hard."
    }, {
        "answer": 0,
        "text": "There are thirty boys and twenty-eight girls in my class. We get along with each other and help with each other. We work hard, too."
    }, {
        "answer": 0,
        "text": "There are thirty boys and twenty eight girls in my class. We do well with each other and can help each other. We study very hard."
    }, {
        "answer": 0,
        "text": "There are thirty boys and twenty-eight girls in our class. They can get along well with each other and they can help each other. We all work very hard."
    }, {
        "answer": 0,
        "text": "There are thirty boys and twenty eight girls in our class. We help each other and learn each other. We get along well with others and we works very hard."
    }, {
        "answer": 0,
        "text": "They are thirty boys and twenty eight girls in my class. We help with each oth. We study hard."
    }, {
        "answer": 0,
        "text": "There are thirty boys and twenty eight girls in my class. We get along well with each other and help each other. We also very work hard."
    }, {
        "answer": 0,
        "text": "There are thirty boys and twenty eight girls in my class. We get along well with each other and we help each other. We study hard."
    }, {
        "answer": 0,
        "text": "There are thirty boys and twenty eight girls in my class. Everyone gets on well with each other and often helps others. We work very hard."
    }, {
        "answer": 0,
        "text": "There are thirty boys and twenty eight girls in our class. We get well along with each other And also help with each other. We work very hard."
    }, {
        "answer": 0,
        "text": "There are thirty boys and twenty eight girls in our class. They are very friendly. They can help each other. We are working hard."
    }, {
        "answer": 0,
        "text": "There are thirty boys in my class and there are twenty-eight girls. Everybody is harmony with each other And they can help with each other. We study very hard."
    }, {
        "answer": 0,
        "text": "There is thirty boys and twenty eight girls in our class and we studied very harmoniously together. We always study very hard."
    }, {
        "answer": 0,
        "text": "There are thirty boys and twenty-eight girls in my class. They are all nice to me. We are all helpful each other. We always help with each other. We works hard."
    }, {
        "answer": 0,
        "text": "In my class, we have thirty boys and twenty eight girls. My classmates are very good. Help with each other. We work very hard."
    }, {
        "answer": 0,
        "text": "There are thirty boys and twenty eight girls in my class. We are very friendly to each other. We can help each other. We work very hard."
    }, {
        "answer": 0,
        "text": "There are thirty boys and twenty eight girls in my class. We are very good and helpful with each other. We are working very hard."
    }, {
        "answer": 0,
        "text": "There are thirty boys, twenty eight girls in my class. My classmates are all nice to each other and help with each other. We study very hard."
    }, {
        "answer": 0,
        "text": "There are thirty boys and twenty-eight girls in my class. We are helps each other. We work hard."
    }, {
        "answer": 0,
        "text": "There are thirty boys and twenty-eight girls in our class. We always help each other. We study very hard."
    }, {
        "answer": 0,
        "text": "There are thirty boys and twenty-eight girls in our class. My classmates are all nice to me. We help with each other. We work hard."
    }, {
        "answer": 0,
        "text": "There are thirty boys and twenty-eight girls. We are nice each other. And help each other. We work hard."
    }]
};

let rank = parseFloat($('#rank').val());
let precision = parseFloat($('#precision').val());

let getScoreRank = (score) => {
    if (score == 4) {
        return "A";
    } else if (score == 3) {
        return "B";
    } else if (score == 2) {
        return "C";
    } else if (score == 1) {
        return "D";
    } else {
        return "D";
    }
};

let sdk = new ChiVoxSDK({
    appKey: Config.appKey,
    mode: mode,
    sigurl: "/token",
    data: {
        audioUrl: "",
        duration: 60000,
        serverParams: {
            coreType: "en.pict.exam",
            refText: A,
            rank: rank,
            precision: precision,
            userId: "chivox tester",
        }
    },

    onInit: (errno, err) => {
        console.info('[ onInit ]:', errno, err);
    },

    onError: (err) => {
        console.error('[ onError ]:', err);
    },

    onBeforeRecord: () => {
        rank = parseFloat($('#rank').val());
        precision = parseFloat($('#precision').val());

        sdk.options.data.serverParams.rank = rank;
        sdk.options.data.serverParams.precision = precision;

        $("#scoreResult .overall").empty();
        $("#scoreResult .pron").empty();
        $("#scoreResult .integrity").empty();
        $("#scoreResult .fluency").empty();
        $("#scoreResult .rhythm").empty();
        $("#scoreResult .tips").empty();
    },

    onScore: (data) => {
        $("#scoreResult .overall").html(data.result.overall);
        $("#scoreResult .pron").html(getScoreRank(data.result.pron));
        $("#scoreResult .integrity").html(getScoreRank(data.result.integrity));
        $("#scoreResult .fluency").html(getScoreRank(data.result.fluency));
        $("#scoreResult .fluency").html(getScoreRank(data.result.rhythm));
        $("#scoreResult .tips").html(data.result.tips);
    },

    onScoreError: (errorType) => { //评分失败的显示 "TIMEOUT", "NO_DATA", ErrorID
        var errorObj = ChiVoxSDK.StatusCode.get(errorType, "cn");
        alert(errorObj.feedback);
    }
});
